/*
 * @Author: typ
 * @Date: 2025-02-24 10:19:45
 * @LastEditors: typ
 * @LastEditTime: 2025-02-26 08:52:19
 * @FilePath: /onemap/vite.config.js
 * @Description: 
 */
import { fileURLToPath, URL } from "node:url";

import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import vueDevTools from "vite-plugin-vue-devtools";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

import path from "path";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd());
  const { VITE_APP_SERVER_IP } = env;
  return {
    plugins: [
      vue(),
      vueDevTools(),
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
      createSvgIconsPlugin({
        iconDirs: [path.resolve(process.cwd(), "src/assets/icons/svg")],
        symbolId: "icon-[dir]-[name]",
        customDomId: 'svg-icons',
        svgoOptions: {
          plugins: [
            {
              name: 'removeAttrs',
              params: {
                attrs: 'fill'
              }
            }
          ]
        }
      }),
    ],

    resolve: {
      alias: {
        "@": fileURLToPath(new URL("./src", import.meta.url)),
      },
    },
    server: {
      host: true,
      open: false,
      proxy: {
        '/dev-api': {
          target: VITE_APP_SERVER_IP,
          changeOrigin: true,
          rewrite: (p) => p.replace(/^\/dev-api/, '')
        },
      }
    },
  };
});